package day0513;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

public class Test9 {
    public static void main(String[] args) {
        Integer[] a={2,6,8,4};
        Integer[] b=Arrays.copyOf(a,3);//{2,6,8}

        //a=Arrays.copyOf(a,3);//{2,6,8}
        //模拟数组缩容。

        a=Arrays.copyOf(a,5);//{2,6,8,4,0}
        System.out.println(Arrays.toString(a));
        a[4]=0;

        Arrays.sort(a);//只能升序排列元素

        System.out.println(Arrays.toString(a));



        // 使用自定义 Comparator 实现降序排序
        Arrays.sort(a,  new Comparator<Integer>(){
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        System.out.println(Arrays.toString(a));




    }
}
